export default class anjian extends Laya.Script {
        /** @prop {name:player, tips:"玩家", type:Node, default:null}*/
        player=null;
        /** @prop {name:zuo, tips:"zuo", type:Node, default:null}*/
        zuo=null;
        /** @prop {name:you, tips:"you", type:Node, default:null}*/
        you=null;
        /** @prop {name:jump, tips:"jump", type:Node, default:null}*/
        jump=null;
        isjump=true;
        GamerOver=false;
        rig=null;
    constructor() { 
        super(); 

        // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    }
    onAwake(){
        Laya.stage.on("GamerOver",this,function(){this.rig.type="static"})
        Laya.stage.on("start",this,this.start)
        this.rig=this.player.getComponent(Laya.RigidBody);
        this.dong();
    }
    start(){
        this.rig.type="dynamic";
        this.player.pos(389,742);
        this.rig.setVelocity({x:0,y:0})
    }
    onUpdate(){

        if(this.player.y<740){
            this.isjump=false;
        }else{
            this.isjump=true;
        }
    }
    dong(){
        this.zuo.on(Laya.Event.MOUSE_DOWN,this,function(){
            var y=this.rig.linearVelocity.y
            this.rig.setVelocity({x:-15,y:y})
        })
        this.zuo.on(Laya.Event.MOUSE_UP,this,function(){
            this.rig.setVelocity({x:0,y:0})
        })
        this.you.on(Laya.Event.MOUSE_DOWN,this,function(){
            var y=this.rig.linearVelocity.y
            this.rig.setVelocity({x:+15,y:y})
            
        })
        this.you.on(Laya.Event.MOUSE_UP,this,function(){
            var y=this.rig.linearVelocity.y
            this.rig.setVelocity({x:0,y:y})
        })
        this.jump.on(Laya.Event.MOUSE_DOWN,this,function(){
            if(this.isjump){
            var x=this.rig.linearVelocity.x
            this.rig.setVelocity({x:x,y:-15})
            this.player.texture="res/胡桃2.png"  
            Laya.SoundManager.playSound("res/sound/player.wav",1);  
            }

        })
    }
}